package jsyf.oa.dao.device;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import jsyf.oa.entity.device.DeviceOutBoundMainEntity;
import jsyf.oa.idao.BaseDao;
import jsyf.oa.ientity.IBaseEntity;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * Created by y on 2018/7/9.
 */
@Repository
public class DeviceOutBoundDao extends BaseDao {
    public DeviceOutBoundDao() {
        super.iBaseEntity = new DeviceOutBoundMainEntity();
    }

    @Override
    public IBaseEntity convertJson2Entity(JSONObject json) {

        return JSON.toJavaObject(json, DeviceOutBoundMainEntity.class);
    }

    public String getId(String sampleId,String type) {
        StringBuffer sql = new StringBuffer();
        sql.append(" select id from T_DVC_OUTBOUND where SAMPLE_ID=? AND TYPE=? order by CREATE_TIME DESC");
        return super.queryForString(sql.toString(), new Object[]{sampleId,type});
    }

    public List<JSONObject> getAttacheById(String id) {
        StringBuffer sb = new StringBuffer();
        sb.append("select * from V_COM_ATTACH where 1 = 1 " + "\n");
        sb.append("AND moduleId=" + " '" + id + "'" + "\n");
        sb.append("AND (attach_module=6 OR attach_module=7 OR attach_module=8)");
        List<JSONObject> attaches = super.queryForJsonList(sb.toString());
        return attaches;
    }

    public  List<JSONObject>  getJsonBySampleId(String contion) {
        StringBuffer sb = new StringBuffer();
        sb.append("SELECT\n" +
                "\tID AS id,\n" +
                "\tSAMPLE_ID AS sampleId,\n" +
                "\tTYPE AS type,\n" +
                "\tPICK_UP_ADDRESS AS pickUpAddress,\n" +
                "\tPICK_UP_CONTACTS AS pickUpContacts,\n" +
                "\tPICK_UP_TELEPHONE AS pickUpTelephone,\n" +
                "\tDELIVERY_ADDRESS AS delivery_address,\n" +
                "\tDELIVERY_CONTACTS AS deliveryContacts,\n" +
                "\tDELIVERY_TELEPHONE AS deliveryTelephone,\n" +
                "\tTRANSPORT_COMPANY AS transport_company,\n" +
                "\tCONTACTS AS contacts,\n" +
                "\tTELEPHONE AS telephone,\n" +
                "\tDRAY_LICENSE AS dray_license,\n" +
                "\tDRIVER_NAME AS driver_name,\n" +
                "\tDRIVER_TEL AS driver_tel,\n" +
                "\tSPECIAL_FEE AS special_fee,\n" +
                "\tDEDUCTION_REMARK AS deduction_remark,\n" +
                "DEDUCTION_FEE AS deduction_fee,\n" +
                "\tREASEON AS reason,\n" +
                "\tTRAFFIC_STARTING AS trafficStarting,\n" +
                "\tTRAFFIC_DESTINATION AS trafficDestination,\n" +
                "\tCONTRACT_ID AS contractId,\n" +
                "\tREASEON AS reason\n" +
                "FROM\n" +
                "\tt_dvc_outbound\n" +
                "WHERE 1=1\n");
        sb.append(contion);
        JSONObject obj = super.queryForJsonObject(sb.toString());
        return null;
    }

}
